import {connect} from 'dva';
import React, {PureComponent} from 'react';
import {Form, Input, Upload, message, Switch, Icon, Select, Radio, Modal} from 'antd';

const FormItem = Form.Item;
const {Option} = Select;

@connect(state => ({
    shop_order: state.shop_order,
}))
@Form.create()
class SendModal extends PureComponent {
    state = {
        item: {
           express_type:'',
           express_no:''
        },
    }
    handleSubmit = (e) => {
        // this.props.dispatch({
        //     type: 'user/status',
        //     payload: {
        //         status,
        //         items: this.state.selectedRows,
        //     },
        //     callback: () => {
        //         this.setState({
        //             selectedRows: [],
        //         });
        //     },
        // });
        this.props.form.validateFields((err, values) => {
            if (!err) {
                values.id = this.props.item.id
                this.props.dispatch({
                    type: 'shop_order/send',
                    payload: values,
                    callback: () => {
                        this.props.form.resetFields();
                        this.handleCancel();
                        if(this.props.onSendComplete){
                            this.props.onSendComplete()
                        }
                    },
                });
            }
        });
    }
   
    handleCancel = () => {
        this.props.dispatch({
            type: 'shop_order/changeShipModal',
            payload: false,
            callback: () => {
               console.log('回调');
            },
        });
    }
   
    render() {
        const {getFieldDecorator} = this.props.form;
        const item = this.state.item;
        const {shop_order: { shipLoading, shipModal}} = this.props;

        const formItemLayout = {
            labelCol: {
                span: 6,
            },
            wrapperCol: {
                span: 14,
            },
        };
        return (
          <Modal
            onOk={this.handleSubmit}
            confirmLoading={shipLoading}
            onCancel={this.handleCancel}
            title="订单发货"
            visible={shipModal}
          >
            <Form onSubmit={this.handleSubmit}>
            <FormItem  {...formItemLayout} label="快递类型" hasFeedback>
                {getFieldDecorator('express_type', {
                            initialValue: item.express_type,
                            rules: [
                                {
                                    required: true,
                                    message: '请选择快递类型',
                                },
                            ],
                        })(
                        <Select >
                            <Option value='顺丰'>顺丰</Option>
                            <Option value='圆通'>圆通</Option>
                            <Option value='申通'>申通</Option>
                            <Option value='韵达'>韵达</Option>
                            <Option value='EMS'>EMS</Option>
                        </Select>)}
              </FormItem>
              <FormItem  {...formItemLayout} label="快递单号" hasFeedback>
                {getFieldDecorator('express_no', {
                            initialValue: item.express_no,
                            rules: [
                                {
                                    required: true,
                                    message: '快递单号不能为空',
                                },
                            ],
                        })(<Input />)}
              </FormItem>
             
            </Form>
          </Modal>
        );
    }
}


export default Form.create()(SendModal);
